package com.xrui.xml;
import java.io.FileNotFoundException;
import java.io.FileReader;

import javax.xml.stream.FactoryConfigurationError;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.Characters;
import javax.xml.stream.events.XMLEvent;

public class StreamReader {

        public static void main(final String[] args) {
            try {
                FileReader reader = new FileReader("c:\\Work\\DevTasks\\Code\\TrcsFanout\\output - Copy\\ThomsonReutersClassificationSchemes.Industry.All.2.2019-07-11-0000.Full.007.xml");
                XMLInputFactory factory = XMLInputFactory.newInstance();
                factory.setProperty("javax.xml.stream.isCoalescing",Boolean.TRUE);
                XMLEventReader xereader = factory.createXMLEventReader(reader);
                while(xereader.hasNext()){
                    XMLEvent e = xereader.nextEvent();
                    if(e.isCharacters()){
                        Characters cdata = e.asCharacters();
                        if(cdata.isWhiteSpace()) continue;
                        System.out.println(cdata.getData());
                    }
                }
                xereader.close();
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IllegalArgumentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (FactoryConfigurationError e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (XMLStreamException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }



}
